<template>
  <div class="orderManagement-container">
    <vab-query-form>
      <vab-query-form-top-panel :span="24">
        <el-form
          :model="queryForm"
          label-width="120px"
          style="width: 100%"
          @submit.native.prevent
        >
          <el-row :gutter="10">
            <el-col :xl="8" :md="12" :xs="12">
              <el-form-item label="组织:">
                 <el-checkbox-group v-model="queryForm.organizationCondition">
                    <el-checkbox-button label="加盟店" />
                    <el-checkbox-button label="渠道店" />
                  </el-checkbox-group>
              </el-form-item>
            </el-col>
            <el-col :xl="8" :md="12" :xs="12">
              <el-form-item label="客户组织:">
                <el-select
                  v-model="queryForm.organizationCode"
                  :disabled="queryForm.organizationCondition.length > 0"
                  placeholder="请选择客户组织"
                  clearable
                >
                  <el-option
                    v-for="item in deptList"
                    :key="item.fnumber"
                    :label="item.fname"
                    :value="item.fnumber"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xl="8" :md="12" :xs="12">
              <el-form-item label="客户分类:">
                <el-select
                  v-model="queryForm.customerTypeCode"
                  :disabled="queryForm.organizationCondition.length > 0"
                  placeholder="请选择客户分类"
                  clearable
                >
                  <el-option
                    v-for="item in customerTypeList"
                    :key="item.fnumber"
                    :label="item.fnumber + '(' + item.fname + ')'"
                    :value="item.fnumber"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xl="8" :md="12" :xs="12">
              <el-form-item label="客户名称:">
                <el-input
                  v-model.trim="queryForm.customerName"
                  placeholder="请输入客户名称"
                  clearable
                  @keyup.enter.native="queryData()"
                />
              </el-form-item>
            </el-col>
            <el-col :xl="8" :md="12" :xs="12">
              <el-form-item label="业务员名称:">
                <el-input
                  v-model.trim="queryForm.bizName"
                  placeholder="请输入业务员"
                  clearable
                  @keyup.enter.native="queryData()"
                />
              </el-form-item>
            </el-col>
            <el-col :xl="8" :md="12" :xs="12">
              <el-form-item label="物流线路:" prop="wuliuCode">
                <el-select
                  v-model="queryForm.wuliuCode"
                  multiple
                  placeholder="请选择物流线路"
                  clearable
                  filterable
                  @change="queryData()"
                >
                  <el-option
                    v-for="(item, index) in wuliuList"
                    :key="index"
                    :value="item.fnumber"
                    :label="item.fdataValue"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xl="8" :md="12" :xs="12">
              <el-form-item label="金蝶单号:" prop="erpOrderNo">
                <el-input
                  v-model.trim="queryForm.erpOrderNo"
                  placeholder="请输入金蝶单号"
                  clearable
                  @keyup.enter.native="queryData()"
                />
              </el-form-item>
            </el-col>
            <el-col :xl="8" :md="12" :xs="12">
              <el-form-item label="审核状态:">
                <el-select
                  v-model="queryForm.status"
                  placeholder="请选择审核状态"
                  clearable
                  @change="queryData()"
                >
                  <el-option value="0" label="未审核"></el-option>
                  <el-option value="1" label="已审核"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-col :xl="8" :md="12" :xs="12">
            <el-form-item label="下单时间:">
              <el-date-picker
                v-model="value1"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :clearable="true"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :xl="8" :md="12" :xs="12">
            <el-form-item label="要货日期:">
              <el-date-picker
                v-model="value2"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :xl="8" :md="12" :xs="12">
            <el-form-item>
              <el-button
                icon="el-icon-search"
                type="primary"
                @click="queryData"
              >
                查询
              </el-button>
            </el-form-item>
          </el-col>
        </el-form>
      </vab-query-form-top-panel>
      <vab-query-form-bottom-panel :span="24">
        <el-button
          v-permissions="['admin', 'kefu']"
          icon="el-icon-plus"
          type="primary"
          style="margin-right: 10px"
          :disabled="disabled"
          @click="handleEdit"
        >
          审批订单
        </el-button>

        <el-button
          v-permissions="['admin', 'kefu']"
          icon="el-icon-check"
          type="success"
          style="margin-right: 10px"
          :disabled="disabled"
          @click="auditAgaian"
        >
          重新审批订单
        </el-button>

        <!--<el-button
          v-permissions="['admin', 'kefu']"
          icon="el-icon-download"
          type="success"
          style="margin-left: 10px"
          @click="handleExport"
        >
          导出订单
        </el-button>-->
        <el-button
          v-permissions="['admin', 'kefu']"
          icon="el-icon-download"
          type="warning"
          style="margin-left: 10px; color: black"
          :disabled="packageDisabled"
          @click="handlePackageExport"
        >
          导出装箱单
        </el-button>
        <el-button
          v-permissions="['admin', 'kefu']"
          icon="el-icon-bottom"
          type="danger"
          style="margin-left: 10px"
          @click="handleDriverOrderExport"
        >
          导出司机专用配送单
        </el-button>
      </vab-query-form-bottom-panel>
    </vab-query-form>

    <el-table
      ref="orderTable"
      v-loading="listLoading"
      :height="height"
      :data="list"
      :element-loading-text="elementLoadingText"
      :row-class-name="tableRowClassName"
      border
      stripe
      @selection-change="setSelectRows"
    >
      <el-table-column
        show-overflow-tooltip
        type="selection"
        tooltip-effect="dark"
        :selectable="checkSelect"
      ></el-table-column>
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-table :data="props.row.orderDetailEntities" border stripe>
            <el-table-column
              prop="materialName"
              label="物料名称"
              width="250"
            ></el-table-column>

            <el-table-column
              prop="materialCode"
              label="物料编码"
              align="center"
              width="100"
            ></el-table-column>

            <el-table-column
              prop="specName"
              label="规格名称"
              width="150"
              align="center"
            ></el-table-column>

            <el-table-column
              prop="specCode"
              label="套餐明细"
              width="150"
              align="left"
            ></el-table-column>

            //数量定制
            <el-table-column prop="num" label="数量" width="80" align="center">
              <template slot-scope="childProps">
                <span v-if="childProps.row.materialCode === '715002'">
                  {{ parseFloat((childProps.row.num * 9) / 500).toFixed(3) }}
                </span>
                <span v-else-if="childProps.row.materialCode === '715001'">
                  {{ parseFloat((childProps.row.num * 3) / 500).toFixed(3) }}
                </span>
                <span v-else-if="childProps.row.materialCode === '715003'">
                  {{ parseFloat((childProps.row.num * 4.5) / 500).toFixed(3) }}
                </span>
                <span v-else>{{ childProps.row.num }}</span>
              </template>
            </el-table-column>
            //出库数量定制
            <el-table-column prop="outstockQty" label="出库数量" width="80" align="center">
              <template slot-scope="childProps">
                <span v-if="childProps.row.materialCode === '715002'">
                  {{ parseFloat((childProps.row.outstockQty * 9) / 500).toFixed(3) }}
                </span>
                <span v-else-if="childProps.row.materialCode === '715001'">
                  {{ parseFloat((childProps.row.outstockQty * 3) / 500).toFixed(3) }}
                </span>
                <span v-else-if="childProps.row.materialCode === '715003'">
                  {{ parseFloat((childProps.row.outstockQty * 4.5) / 500).toFixed(3) }}
                </span>
                <span v-else>{{ childProps.row.outstockQty }}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="specName"
              label="单价(元)"
              width="80"
              align="right"
            >
              <template slot-scope="childProps">
                {{ (childProps.row.price / childProps.row.num).toFixed(2) }}
              </template>
            </el-table-column>

            <el-table-column
              prop="price"
              label="小计(元)"
              width="100"
              align="right"
            >
              <template slot-scope="childProps">
                {{ childProps.row.price.toFixed(2) }}
              </template>
            </el-table-column>

            <el-table-column
              prop="deliveryDate"
              label="要货日期"
              width="120"
            ></el-table-column>

            <el-table-column prop="id" label="" align="center" width="320">
              <template slot-scope="childProps">
                <span
                  v-if="
                    childProps.row.materialCode !== '715001' &&
                    childProps.row.materialCode !== '715002' &&
                    childProps.row.materialCode != '715003' &&
                    childProps.row.materialCode != '603163' &&
                    childProps.row.materialCode != '715013' &&
                    childProps.row.materialCode != 'yunfei'
                  "
                >
                  <el-button
                    icon="el-icon-edit"
                    type="primary"
                    @click="handleEditDetailsNum(childProps.row)"
                  >
                    修改数量
                  </el-button>

                  <el-button
                    v-permissions="['admin', 'staff']"
                    icon="el-icon-edit"
                    type="success"
                    @click="handleEditDetailsPrice(childProps.row)"
                  >
                    修改单价
                  </el-button>

                  <el-button
                    icon="el-icon-delete"
                    type="danger"
                    @click="handleDeleteOrderDetails(childProps.row)"
                  >
                    删除
                  </el-button>
                </span>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </el-table-column>

      <el-table-column
        show-overflow-tooltip
        prop="status"
        label="订单状态"
        width="80"
        align="center"
      >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 0" type="danger">
            <i class="el-icon-lock"></i>未审
          </el-tag>
          <el-tag  v-else>
            <i class="el-icon-check"></i>已审
          </el-tag>
        </template>
      </el-table-column>

      <el-table-column
        show-overflow-tooltip
        prop="customerName"
        width="230"
        fixed
        label="客户名称"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        width="180"
        prop="createTime"
        label="下单时间"
        align="center"
      ></el-table-column>

      <el-table-column
        show-overflow-tooltip
        prop="orderDetailEntities[0].deliveryDate"
        width="120"
        align="left"
        label="要货日期"
      ></el-table-column>

      <el-table-column
        show-overflow-tooltip
        width="180"
        prop="orderNo"
        label="审批日期"
        align="center"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.status == 1">
            {{ scope.row.updateTime }}
          </span>
          <span v-else type="info"></span>
        </template>
      </el-table-column>

      <el-table-column
        show-overflow-tooltip
        prop="bizName"
        width="80"
        align="center"
        label="业务员"
      ></el-table-column>
      <!--<el-table-column
        show-overflow-tooltip
        prop="goodsNumber"
        width="100"
        align="center"
        label="物料数量"
      ></el-table-column>-->
      <el-table-column
        show-overflow-tooltip
        prop="amount"
        width="120"
        align="right"
        label="总价(元)"
      >
        <template slot-scope="scope">
          <span>
            {{ scope.row.amount.toFixed(2) }}
          </span>
        </template>
      </el-table-column>

      <!--<el-table-column
        show-overflow-tooltip
        width="300"
        prop="orderNo"
        label="订单编号"
        align="center"
      ></el-table-column>-->

      <el-table-column
        show-overflow-tooltip
        width="300"
        prop="wuliuName"
        label="物流名称"
      ></el-table-column>

      <el-table-column
        show-overflow-tooltip
        prop="erpOrderNo"
        width="160"
        align="center"
        label="金蝶订单编号"
      ></el-table-column>

      <el-table-column
        show-overflow-tooltip
        prop="fnote"
        width="200"
        align="left"
        label="备注"
      ></el-table-column>

      <el-table-column
        show-overflow-tooltip
        label="操作"
        width="380"
        fixed="right"
      >
        <template #default="{ row }">
          <el-switch
            v-model="row.version"
            :active-value="1"
            :inactive-value="0"
            active-text="不打印"
            inactive-text="打印"
            style="margin-left: 10px"
            @change="handleExportSign(row)"
          ></el-switch>

          <el-tooltip
            class="item"
            effect="dark"
            content="修改发货日期"
            placement="bottom"
          >
            <el-button
              icon="el-icon-date"
              type="success"
              @click="handleEditDeliveryDate(row)"
            ></el-button>
          </el-tooltip>

          <el-tooltip
            class="item"
            effect="dark"
            content="修改备注"
            placement="bottom"
          >
            <el-button
              icon="el-icon-document"
              type="primary"
              @click="handleEditMemo(row)"
            ></el-button>
          </el-tooltip>

          <el-tooltip
            class="item"
            effect="dark"
            content="修改物流线路"
            placement="bottom"
          >
            <el-button
              icon="el-icon-share"
              type="warning"
              style="color: black"
              @click="handleEditWuliu(row)"
            ></el-button>
          </el-tooltip>

          <el-tooltip
            class="item"
            effect="dark"
            content="删除订单"
            placement="bottom"
          >
            <el-button
              icon="el-icon-delete"
              type="danger"
              @click="handleDelete(row)"
            ></el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNo"
      :page-size="queryForm.pageSize"
      :layout="layout"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    ></el-pagination>
    <date-picker ref="edit" @fetch-data="fetchData"></date-picker>
    <edit-memo ref="editMemo" @fetch-data="fetchData"></edit-memo>
    <edit-wuliu ref="editWuliu" @fetch-data="fetchData"></edit-wuliu>
    <edit-details-num ref="editNum" @fetch-data="syncOrder"></edit-details-num>
    <edit-details-price
      ref="editPrice"
      @fetch-data="syncOrder"
    ></edit-details-price>
    <package-dialog ref="packageDialog"></package-dialog>
  </div>
</template>

<script>
import {
  getOrganization,
  getCustomerTypeList,
  getCustomerTypeChildrenList, getDept, getCustomerLastTypeList,
} from '@/api/erp'

  import {
    getList,
    auditOrders,
    doDelete,
    doDeleteOrderDetails,
    doUpdateExportStatus,
  } from '@/api/order'
  import { auditCustomers } from '@/api/customerManagement'
  import { baseURL } from '@/config/settings'
  import { getWuliuList } from '@/api/erp'
  import { getShoukuanList } from '@/api/erp'
  import { getCompanyList } from '@/api/erp'
  import DatePicker from './components/datePicker'

  import EditMemo from './components/editMemo'
  import EditWuliu from './components/editWuliu'
  import EditDetailsPrice from './components/editDetailsPrice'

  import EditDetailsNum from './components/editDetailsNum'
  import PackageDialog from './components/packageDialog'
  import store from "@/store";

  const dayjs = require('dayjs')
  export default {
    name: 'OrderManagement',
    components: {
      EditMemo,
      EditWuliu,
      EditDetailsNum,
      EditDetailsPrice,
      DatePicker,
      PackageDialog,
    },
    data() {
      return {
        list: null,
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        selectRows: [],
        elementLoadingText: '正在加载...',
        value1: [],
        value2: [],
        //物流
        wuliuList: [],
        disabled: false,
        approvedCustomerList: [],
        packageDisabled: true,
        //客户组织
        deptList: [],
        //客户类型
        customerTypeList: [],
        //客户小分类
        customerTypeChildrenList: [],
        queryForm: {
          pageNo: 1,
          pageSize: 50,
          customerName: '',
          bizName: '',
          wuliuCode: [],
          start: '',
          end: '',
          deliveryStart: '',
          deliveryEnd: '',
          status: '',
          organizationCode: '',
          customerTypeCode: '',
          customerTypeChildCode: '',
          organizationCondition:[],
        },
      }
    },
    computed: {
      height() {
        return this.$baseTableHeight(2)
      },
    },
    watch:{
      'queryForm.organizationCondition'(val){
          if(val.length > 0){
          this.queryForm.organizationCode = ''
          this.queryForm.customerTypeCode = ''
          this.queryForm.customerTypeChildCode = ''
          }
      }
    },
    created() {
      this.value1 = [new Date(), new Date()]
      this.value2 = ''
      this.initWuliuList()
      this.initApprovedCustomerList()
      this.init()
      let condStr = sessionStorage.getItem(this.$store.getters['user/username'] + ":orders.search")
      if (condStr) {
        let cond = JSON.parse(condStr)
        Object.assign(this.queryForm, cond)
        if (this.queryForm.start && this.queryForm.end) {
          this.value1 = [ dayjs(this.queryForm.start).toDate(), dayjs(this.queryForm.end).toDate() ]
          this.queryForm.start = null
          this.queryForm.end = null
        } else {
          this.value1 = []
        }
        if (this.queryForm.deliveryStart && this.queryForm.deliveryEnd) {
          this.value2 = [ dayjs(this.queryForm.deliveryStart).toDate(), dayjs(this.queryForm.deliveryEnd).toDate() ]
          this.queryForm.deliveryStart = null
          this.queryForm.deliveryEnd = null
        }
        // if (this.queryForm.customerTypeCode) {
        //   this.selectCustomerType(this.queryForm.customerTypeCode, true)
        // }
      } else {
        this.value1 = [ new Date(), new Date() ]
      }
      this.fetchData()
    },
    methods: {
      //客户大分类
      // async selectCustomerType(event, getOnly) {
      //   if (!getOnly) {
      //     this.queryForm.customerTypeChildCode = ''
      //     this.queryForm.customerTypeChildName = ''
      //   }
      //   this.customerTypeChildrenList = []
      //
      //   //业务员
      //   // this.bizList = []
      //   // this.queryForm.bizCode = ''
      //   // this.queryForm.bizName = ''
      //
      //   if (event) {
      //     const res = await getCustomerTypeChildrenList(event)
      //     this.customerTypeChildrenList = res
      //     if (!getOnly) {
      //       if (res.length > 0) {
      //         this.queryForm.customerTypeChildName = res[0].fname
      //         this.queryForm.customerTypeChildCode = res[0].fnumber
      //         //获取业务员
      //         // this.bizList = await getBizList(
      //         //   res[0].fname,
      //         //   this.queryForm.organizationCode
      //         // )
      //       }
      //     }
      //   }
      // },

      async init() {
        let res = await getDept()
        this.deptList = res
        res = await getCustomerLastTypeList()
        this.customerTypeList = res
      },
      tableRowClassName({ row, rowIndex }) {
        if (rowIndex % 2 == 1) {
          return 'yellow'
        } else {
          return ''
        }
      },

      async initWuliuList() {
        //物流路线
        this.wuliuList = await getWuliuList()
      },

      async initApprovedCustomerList() {
        this.packageDisabled = true
        this.approvedCustomerList = await auditCustomers()
        this.packageDisabled = false
      },
      checkSelect(row, index) {
        return true
      },
      setSelectRows(val) {
        this.selectRows = val
      },

      //审核订单
      handleEdit() {
        const _this = this

        if (_this.selectRows.length == 0) {
          this.$baseAlert('请至少选择一条数据进行审批！')
          return
        }

        this.$baseConfirm('你确定要审批该订单吗？', null, async () => {
          _this.listLoading = true
          _this.disabled = true
          _this.selectRows = _this.$baseLodash.filter(
            _this.selectRows,

            function (o) {
              return o.status != 1
            }
          )
          let ids = _this.selectRows.map((p) => p.id)
          auditOrders({ orderIds: ids })
            .then(function (res) {
              _this.$baseMessage('订单审批完成！', 'success')
              _this.fetchData()
              _this.listLoading = false
              _this.disabled = false
            })
            .catch(function (res) {
              /*_this.$baseMessage('订单审核发生错误', 'error')*/
              if (res.status == 400) {
                let errors = res.data.errors
                errors.forEach((element) => {
                  _this.$notify({
                    title: '提示',
                    message: element.message,
                    duration: 0,
                  })
                })
              }
              _this.fetchData()
              _this.listLoading = false
              _this.disabled = false
            })
        })
      },

      //重新审核订单
      auditAgaian() {
        const _this = this

        if (_this.selectRows.length == 0) {
          this.$baseAlert('请至少选择一条数据进行再审批！')
          return
        }

        _this.selectRows = _this.$baseLodash.filter(_this.selectRows, function (
          o
        ) {
          return o.status == 1
        })
        let ids = _this.selectRows.map((p) => p.id)
        if (ids.length == 0) {
          this.$baseAlert('请至少选择一条审批过的数据进行再次审批！')
          return
        }

        this.$baseConfirm(
          '你确定要重新审批该订单吗？请确保金蝶中已经删除对应的订单！',
          null,
          async () => {
            _this.listLoading = true
            _this.disabled = true

            auditOrders({ orderIds: ids })
              .then(function (res) {
                _this.$baseMessage('订单重新审批完成！', 'success')
                _this.fetchData()
                _this.listLoading = false
                _this.disabled = false
              })
              .catch(function (res) {
                /*_this.$baseMessage('订单审核发生错误', 'error')*/
                if (res.status == 400) {
                  let errors = res.data.errors
                  errors.forEach((element) => {
                    _this.$notify({
                      title: '提示',
                      message: element.message,
                      duration: 0,
                    })
                  })
                }
                _this.fetchData()
                _this.listLoading = false
                _this.disabled = false
              })
          }
        )
      },

      //修改发货日期
      async handleEditDeliveryDate(row) {
        if (row.id) {
          this.$refs['edit'].showEdit(row)
        }
      },

      //修改备注
      async handleEditMemo(row) {
        if (row.id) {
          this.$refs['editMemo'].showEdit(row)
        }
      },

      //修改物流线路
      async handleEditWuliu(row) {
        if (row.id) {
          this.$refs['editWuliu'].showEdit(row, this.wuliuList)
        }
      },

      //修改物料数量
      async handleEditDetailsNum(row) {
        if (row.id) {
          this.$refs['editNum'].showEdit(row)
        }
      },

      //修改物料单价
      async handleEditDetailsPrice(row) {
        if (row.id) {
          this.$refs['editPrice'].showEdit(row)
        }
      },

      async handleExport() {
        this.queryForm.start = dayjs(this.value1[0]).format('YYYY-MM-DD')
        this.queryForm.end = dayjs(this.value1[1]).format('YYYY-MM-DD')

        const _this = this

        if (_this.selectRows.length == 0) {
          this.$baseAlert('请至少选择一条数据进行导出！')
          return
        }

        this.$baseConfirm('你确定要导出当前项吗', null, async () => {
          let ids = _this.selectRows.map((p) => p.id)
          //_this.listLoading = true
          location.href = baseURL + '/erp/order/export?ids=' + ids
        })

        //修改成可以选择
        //location.href = baseURL + '/erp/order/export?start='+this.queryForm.start+'&end=' + this.queryForm.end
        //await exportXls(this.queryForm)
      },

      //按装箱进行导出
      handlePackageExport() {
        this.$refs['packageDialog'].showDialog(
          this.wuliuList,
          'package',
          this.approvedCustomerList
        )
      },
      //司机专业配送单
      handleDriverOrderExport() {
        this.$refs['packageDialog'].showDialog(this.wuliuList, 'driver', null)
      },

      //删除订单
      handleDelete(row) {
        if (row.id) {
          this.$baseConfirm('你确定要删除该订单吗', null, async () => {
            await doDelete(row.id)
            this.$baseMessage('订单删除成功', 'success')
            this.fetchData()
          })
        }
      },

      //删除订单明细
      handleDeleteOrderDetails(row) {
        if (row.id) {
          this.$baseConfirm('确定要删除订单明细吗？', null, async () => {
            await doDeleteOrderDetails({ id: row.id, orderId: row.orderId })
            this.$baseMessage('订单明细删除成功！', 'success')
            this.syncOrder(row.orderId)
          })
        }
      },

      async handleExportSign(row) {
        await doUpdateExportStatus({ id: row.id, status: row.version })
      },

      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNo = val
        this.fetchData()
      },
      queryData() {
        this.queryForm.pageNo = 1
        this.fetchData()
      },
      async fetchData() {
        this.listLoading = true

        this.queryForm.start = null
        this.queryForm.end = null
        if (this.value1 && this.value1.length > 0) {
          this.queryForm.start = dayjs(this.value1[0]).format('YYYY-MM-DD')
          this.queryForm.end = dayjs(this.value1[1]).format('YYYY-MM-DD')
        }

        this.queryForm.deliveryStart = null
        this.queryForm.deliveryEnd = null
        if (this.value2 && this.value2.length > 0) {
          this.queryForm.deliveryStart = dayjs(this.value2[0]).format(
            'YYYY-MM-DD'
          )
          this.queryForm.deliveryEnd = dayjs(this.value2[1]).format(
            'YYYY-MM-DD'
          )
        }

        sessionStorage.setItem(this.$store.getters['user/username'] + ":orders.search", JSON.stringify(this.queryForm))

        const { records, totalElement } = await getList(this.queryForm)
        this.list = records
        this.total = totalElement

        setTimeout(() => {
          this.listLoading = false
        }, 300)
      },
      async syncOrder(orderId) {
        // this.queryForm.pageNo = 1
        // this.queryForm.orderId = orderId
        const { records, totalElement } = await getList({
          pageNo: 1,
          pageSize: 1,
          orderId: orderId,
        })
        var index = this.list.findIndex((item) => item.id == orderId)
        this.$set(this.list, index, records[0])

        setTimeout(() => {
          this.$refs['orderTable'].toggleRowExpansion(this.list[index], true)
        }, 50)
      },
    },
  }
</script>

<style lang="scss" scoped>
  ::v-deep {
    .el-select,
    .el-input {
      width: 100%;
    }
  }
</style>
